<?php
require 'include/library.inc.php';

$_SESSION['LOGIN_REDIRECT'] = $_SERVER['PHP_SELF'];

require 'include/user_login.inc.php';
require 'include/paging.inc.php';

$sql = 'SELECT
			first_name,
			last_name,
			married,
			gender,
			hometown_country_id,
			date_of_birth,
			phone
		FROM
			users
		WHERE
			user_id = '.$_SESSION['USER_SID'].'
	';
$row_user = mysql_fetch_assoc(query($sql));


$sql = "SELECT
			o.order_id,
			o.registration_fee,
			date_format(o.creation_datetime, \"%Y/%m/%d\") AS creation_date,
			s.name AS school_name,
			os.name AS order_status
		FROM
		  	orders AS o,
			schools AS s,
			users AS u,
			order_status AS os
		WHERE
			o.school_id = s.school_id
		AND
			o.user_id = u.user_id
		AND
			u.user_id = ".$_SESSION['USER_SID']."
		AND
			o.order_status_id = os.order_status_id
		  ";
if (!isset($_GET['sort'])) $_GET['sort'] = 1;
if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 1;

$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(1=>"Order ID"), 100);
$result = $paging->query();

head($row_user['first_name']."'s Profile","",100);
?>
	
    	<div id="content">
        	<h2><?=$row_user['first_name']?>'s Profile</h2><br>
            
            <?php if ($_SESSION['message']) { ?>
			<div class="message green">
				<?=$_SESSION['message']?>
			</div>
			<?php unset($_SESSION['message']); } ?>
            
            <div class="padding">
        	
            <small>Fisrt Name, Last Name:</small><br>
            <h3><?=$row_user['first_name']?> <?=$row_user['last_name']?></h3><br>
            
         
			
            <a href="profile_edit.php">Edit my personal information</a>
            
            <br><br>
            
            <h2>Orders (<?=$paging->count()?>)</h2>
            
            <table class="listing" width="100%" cellpadding="0" cellspacing="0">
			<thead>
				<tr>
                    <td>Order ID</td>
                    <td>School</td>
                    <td>Application fee</td>
                    <td>Status</td>
                    <td>Options</td>
				</tr>
			</thead>
			<tbody>
			<?php
	  
			  $i=1;
			  while ($row = mysql_fetch_object($result)) {				  
			?>
                <tr class="<?=(($i%2)?"none":"zebra")?>">
                    
                    <td>
                        <a href="order_edit.php?order_id=<?=$row->order_id?>" title="Review"><?=number_pad($row->order_id,5)?></a>
                        from <?=$row->creation_date?>
                    </td>
                    
                    <td>
                    	<?=$row->school_name?>
                    </td>
                    
                    <td>
                    <?=$_SESSION["curr_sim"]?><?=round($row->registration_fee*$_SESSION["currency_value"])?>
                    	
                    </td>
                                                
                    <td>
                    	<?=$row->order_status?>
                    </td>
                                
                    <td class="icons">
                                            
                        <a href="order_edit.php?order_id=<?=$row->order_id?>" class="edit" title="Review">Review</a>
                        
                    </td>
                    
                </tr>
                    
			 <?php
                  $i++;    
                } 
             ?>	
		 		  
			</tbody>
		</table>
        
        <div class="pagingwrap"><div class="paging">
			<?=$paging->display()?>
        </div></div>
            
            
            
            
            
            </div>
        </div>
        
            
<?php foot(); ?>